<template>
  <div class="app-container">
    <div class="content">
      <div class="rightHeader">
        <div class="header">
          <div class="logoBox">
            <img src="@/assets/images/logo.png" alt="" />
          </div>
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="large"
            :inline="true"
            :rules="queryRules"
            label-width="110px"
          >
            <el-form-item label="楼层:" prop="floor">
              <el-select
                v-model="queryParams.floor"
                placeholder="请选择楼层"
                clearable
              >
                <el-option
                  v-for="dict in dict.type.floor_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
              <!-- <el-input
                v-model="queryParams.floor"
                placeholder="请输入楼层"
                clearable
                @keyup.enter.native="handleQuery"
              /> -->
            </el-form-item>
            <el-form-item label="批号:" prop="lotatt04">
              <el-input
                v-model="queryParams.lotatt04"
                placeholder="请输入批号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="拼箱号:" prop="picktotraceId">
              <el-input
                v-model="queryParams.picktotraceId"
                placeholder="请输入拼箱号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="69码:" prop="alternateSku">
              <el-input
                v-model="queryParams.alternateSku"
                placeholder="请输入69码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <!-- <el-form-item label="电子监管码:" prop="regulatoryCode">
              <el-input
                v-model="queryParams.regulatoryCode"
                placeholder="请输入电子监管码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item> -->
            <el-form-item>
              <div class="btns">
                <el-button
                type="primary"
                icon="el-icon-search"
                size="medium"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button
                type="primary"
                icon="el-icon-refresh"
                size="medium"
                @click="resetQuery"
                >重置</el-button
              >
              <el-button
                type="primary"
                icon="el-icon-folder-add"
                size="medium"
                @click="addMultiDrug"
                >添加多药</el-button
              >
              </div>
            </el-form-item>
          </el-form>
        </div>
        <div class="footer">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
          <span @click="goBack">退出</span>
        </div>
      </div>
      <div class="wtable">
        <el-table
          :data="tableData"
          class="tableContent"
          height="700"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
        >
          <el-table-column prop="floor" label="楼层" align="center">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.floor_type"
                :value="scope.row.floor"
              />
            </template>
          </el-table-column>
          <el-table-column prop="checkNo" label="复核台" align="center">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.location_no"
                :value="scope.row.checkNo"
              />
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="regulatoryCode"
            label="电子监管码"
            align="center"
          ></el-table-column> -->
          <el-table-column
            prop="alternateSku"
            label="69码"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="picktotraceId"
            label="拼箱号"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="sku"
            label="商品代码"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="skuName"
            label="商品名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="lotatt04"
            label="批号"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="qtyPicked"
            label="拣货数量"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="locationId"
            label="库位"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="pickWho"
            label="拣货人"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="checkWho"
            label="复核人"
            align="center"
          ></el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                >异常查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="handleQuery"
          />
        </div>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="dialogVisible = false"
    >
      <span>未查询到数据</span>
    </el-dialog>
    <el-dialog
      :title="title"
      :visible.sync="dialogFormVisible"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        :model="form"
        ref="form"
        size="small"
        :inline="true"
        :rules="rules"
        label-width="140px"
      >
        <el-form-item label="复核台" prop="checkNo">
          <el-select
            v-model="form.checkNo"
            ref="locationNoInput"
            filterable
            placeholder="请选择复核台"
          >
            <el-option
              v-for="dict in dict.type.location_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有电子监管码" prop="isCode">
          <el-radio-group v-model="form.isCode">
            <!-- <el-radio :label="N">否</el-radio>
            <el-radio :label="Y">是</el-radio> -->
            <el-radio
              v-for="dict in dict.type.sys_common_code"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item
          v-if="form.isCode === 'Y'"
          label="监管码"
          prop="regulatoryCode"
        >
          <el-input
            v-model="form.regulatoryCode"
            clearable
            placeholder="请输入监管码"
          ></el-input>
        </el-form-item> -->
        <el-form-item
          v-show="form.isCode === 'Y'"
          :rules="regulatoryCodeRules"
          label="电子监管码"
          prop="regulatoryCode"
        >
          <el-input
            v-model="form.regulatoryCode"
            clearable
            placeholder="请输入电子监管码"
          ></el-input>
        </el-form-item>
        <el-form-item label="69码" prop="sixCode">
          <el-input
            v-model="form.sixCode"
            @input="handlefocusChange"
            clearable
            placeholder="请输入69码"
          ></el-input>
        </el-form-item>
        <el-form-item label="拼箱号" prop="orderNum">
          <el-input
            v-model="form.orderNum"
            ref="orderNumInput"
            placeholder="请输入拼箱号"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <VueBarcodeScanner :result="form.containerNo" />
    <VueBarcodeScanner :result="form.name1" />
    <VueBarcodeScanner :result="form.name2" />
    <el-dialog
      title="异常信息"
      :visible.sync="dialogAbnormal"
      width="90%"
      append-to-body
      :close-on-click-modal="false"
      custom-class="import-dialog"
    >
      <rowDrugDialog
        :abnormalId="selectedItemId"
        @custom-event="handleClosedialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import { addPosttaobao, getmultidrug } from "@/api/system/multidrug";
import VueBarcodeScanner from "vue-barcode-scanner";
import rowDrugDialog from "@/components/multiDrug/rowDrugdialog";
export default {
  dicts: ["location_no", "sys_common_code", "floor_type"],
  components: {
    VueBarcodeScanner,
    rowDrugDialog,
  },
  data() {
    return {
      // 异常库存冲红信息弹窗
      dialogAbnormal: false,
      // 标题名称
      title: "添加多药信息",
      // 表单弹窗
      dialogFormVisible: false,
      // 弹窗隐藏
      dialogVisible: false,
      // 总条数
      total: 0,
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        picktotraceId: null,
        alternateSku: null,
        lotatt04: null,
        floor: null,
      },
      form: {
        orderNum: null,
        regulatoryCode: null,
        orderNum: null,
        // 是否有追溯码
        isCode: "N",
        // 复核台号
        checkNo: null,
      },
      tableData: [],
      queryRules: {
        picktotraceId: [
          { required: false, message: "请输入拼箱号", trigger: "blur" },
        ],
        alternateSku: [
          { required: false, message: "请输入69码", trigger: "blur" },
        ],
        lotatt04: [{ required: false, message: "请输入批号", trigger: "blur" }],
      },
      rules: {
        orderNum: [
          { required: true, message: "请输入拼箱号", trigger: "blur" },
        ],
        sixCode: [{ required: true, message: "请输入69码", trigger: "blur" }],
        isCode: [
          { required: true, message: "请选择是否有监管码", trigger: "change" },
        ],
        regulatoryCode: [
          { required: false, message: "请输入电子监管码", trigger: "blur" },
        ],
        checkNo: [
          { required: true, message: "请输入复核台号", trigger: "change" },
        ],
      },
      // 父传子的值
      selectedItemId: null,
    };
  },
  computed: {
    regulatoryCodeRules() {
      return this.form.isCode === "Y"
        ? [
            {
              required: true,
              message: "请输入电子监管码",
              trigger: "blur",
            },
          ]
        : [];
    },
  },
  mounted() {
    this.getlist();
  },
  methods: {
    // 子传父关闭弹窗，更新列表
    handleClosedialog() {
      this.dialogAbnormal = false;
      this.getlist();
    },
    getlist() {
      this.loading = true;
      getmultidrug(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    handleQuery() {
      // this.queryParams.pageNum = 1;
      this.getlist();
    },
    // 当69码的位数等于13位时焦点跳转到拼箱号
    handlefocusChange() {
      if (this.form.sixCode.trim().length == 13) {
        this.$refs.orderNumInput.focus();
      }
    },
    // 异常查看
    handleUpdate(row) {
      this.dialogAbnormal = true;
      this.selectedItemId = row.id;
    },
    // 页面添加多药录入信息
    addMultiDrug() {
      this.reset();
      this.dialogFormVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.locationNoInput.focus();
      // });
    },
    // 取消填入表单信息
    cancel() {
      this.dialogFormVisible = false;
      this.reset();
    },
    // 重置表单信息
    reset() {
      this.form = {
        orderNum: undefined,
        sixCode: undefined,
        isCode: "N",
        regulatoryCode: undefined,
        checkNo: undefined,
      };
      this.resetForm("form");
    },
    // 提交表单
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(this.form);
          addPosttaobao(this.form).then((res) => {
            this.dialogFormVisible = false;
            this.getlist();
          });
        }
      });
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goBack() {
      this.$router.push("/subSystem1");
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 0 !important;
  width: 100%;
  height: 100%;
  background: url("../assets/images/hcbanner2.jpg") no-repeat;
  overflow: hidden;
  ::v-deep .el-table__empty-block {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }
  ::v-deep .el-form-item__label {
    color: #fff;
    font-size: 22px;
    font-weight: 400;
  }
  ::v-deep .el-input--small .el-input__inner {
    height: 40px;
  }
  ::v-deep .el-pagination__jump {
    color: #ffffff;
  }
  ::v-deep .el-pagination__total {
    color: #ffffff;
  }
  ::v-deep .el-pagination {
    margin-right: 78px;
  }
  .pagination-container {
    background: transparent;
    margin-top: 5px !important;
    padding: 0px 20px !important;
  }
  .content {
    height: 100%;
  }
  .rightHeader {
    margin-top: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .header {
      display: flex;
      justify-content: flex-start;
      margin-left: 30px;
      .logoBox {
        width: 300px;
        margin-right: 255px;
        margin-top: -60px;
        margin-left: -20px;
        img {
          width: 200%;
        }
      }
      .btns{
        margin-left: 490px;
      }
    }
    .footer {
      display: flex;
      align-items: center;
      cursor: pointer;
      margin-top: -50px;
      color: #ffffff5d;
      font-size: 18px;
      img {
        width: 50%;
      }
      span {
        display: block;
        margin-left: -40px;
        margin-top: 15px;
        font-size: 12px;
      }
    }
  }
  .hname {
    width: 40px;
  }
  .el-button--medium {
    margin-left: 10px;
    font-size: 18px;
  }
  .wtable {
    width: 100%;
    text-align: center;
  }
  .tableContent {
    margin: 0 auto;
    width: 96%;
    margin-top: 0;
  }
  ::v-deep .el-form-item__label {
    color: #fff;
  }
  ::v-deep .el-input {
    width: 100%;
    font-size: 16px;
  }
  ::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
  }
  ::v-deep .el-pagination.is-background .btn-next:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination.is-background .btn-prev:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination span:not([class*="suffix"]) {
    min-width: 56px;
  }
  ::v-deep .el-date-editor .el-range-input {
    font-size: 15px;
  }
  // 点击el-radio出错，解决方法
  ::v-deep .el-radio__original {
    display: none !important; /* 隐藏原生 radio 输入，但仍然允许交互 */
  }
  ::v-deep
    .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled)
    .el-radio__inner {
    box-shadow: none !important;
  }
  // ::v-deep .el-dialog .import-dialog{
  //     height: auto;
  //     max-height: 80vh;
  //     overflow-y: auto;
  // }
  // ::v-deep .el-dialog__body{
  //   max-height: 70vh !important;
  // }
}
</style>